package com.bruce.controller;

import com.bruce.bean.Course;
import com.bruce.service.CourseService;
import com.bruce.service.impl.CourseServiceImpl;
import com.bruce.utils.PageUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author cc
 * @date 2021/7/26 9:26
 * @Description
 */
@WebServlet("/courseServlet.do")
public class CourseController extends HttpServlet {
    CourseService courseService = new CourseServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        String method = req.getParameter("flag");
        switch (method){
            case "page":
                String pageIndex = req.getParameter("pageIndex");
                String type = req.getParameter("type");
                //搜索条件
                String condition = req.getParameter("condition");

                int pagsize = 5;
                PageUtils pageUtils = new PageUtils();
                pageUtils.setPageIndex(Integer.parseInt(pageIndex));
                pageUtils.setPagesize(5);
                PageUtils<Course> resulet = courseService.FindALlCourse(pageUtils);
                req.setAttribute("pageUtils", resulet);
                req.setAttribute("type", type); //搜索条件1 回显搜索条件
                req.setAttribute("condition", condition); //搜索条件2 回显搜索条件
                req.getRequestDispatcher("/admin/queryCourse.jsp").forward(req, resp);
                break;
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
